package com.sxjh.controller.pub;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.common.Result;
import com.sxjh.entity.MaterialCategories;
import com.sxjh.entity.Materials;
import com.sxjh.entity.result.MaterialCategoriesListResult;
import com.sxjh.entity.result.MaterialListResult;
import com.sxjh.service.MaterialCategoriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 物料分类表 前端控制器
 * </p>
 *
 * @author zixin
 * @since 2021-08-27
 */
@RestController
@RequestMapping("/material-categories")
@Api(tags = "物料大类")
public class MaterialCategoriesController extends BaseController {

  @Autowired
  private MaterialCategoriesService materialCategoriesService;

  @ApiOperation("列表")
  @GetMapping
  Result<List<MaterialCategoriesListResult>> list() {
    List<MaterialCategories> list = materialCategoriesService.list(
            new LambdaQueryWrapper<MaterialCategories>()
                    .isNull(MaterialCategories::getDeletedAt)
                    .ne(MaterialCategories::getPid, 0)
                    .select(MaterialCategories::getId, MaterialCategories::getTitle));
    List<MaterialCategoriesListResult> results = copyList(list, MaterialCategoriesListResult::new);
    return Result.ok(results);
  }

}

